from django.db import models
from django.conf import settings

class Profile(models.Model):
    """用户档案模型"""
    user = models.OneToOneField(
        settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE,
        related_name='profile',
        verbose_name='用户'
    )
    
    # 个人信息
    bio = models.TextField(blank=True, verbose_name='个人简介')
    location = models.CharField(
        max_length=100,
        blank=True,
        verbose_name='所在地'
    )
    
    # 游戏统计
    total_battles = models.IntegerField(default=0, verbose_name='总战斗次数')
    won_battles = models.IntegerField(default=0, verbose_name='胜利次数')
    total_characters = models.IntegerField(default=0, verbose_name='创建角色数')
    favorite_character_type = models.CharField(
        max_length=50,
        blank=True,
        verbose_name='最爱角色类型'
    )
    
    # 偏好设置
    language = models.CharField(
        max_length=10,
        default='zh-hans',
        verbose_name='界面语言'
    )
    theme = models.CharField(
        max_length=20,
        default='light',
        verbose_name='界面主题'
    )
    notification_settings = models.JSONField(
        default=dict,
        verbose_name='通知设置'
    )
    
    # 社交关系
    friends = models.ManyToManyField(
        'self',
        blank=True,
        symmetrical=True,
        verbose_name='好友'
    )
    blocked_users = models.ManyToManyField(
        settings.AUTH_USER_MODEL,
        blank=True,
        related_name='blocked_by_profiles',
        verbose_name='屏蔽用户'
    )
    
    class Meta:
        verbose_name = '用户档案'
        verbose_name_plural = '用户档案'
        
    def __str__(self):
        return f"{self.user.username}的档案"
